Brief description of gcov data files

Contents|Index|Previous|Next
Brief description of `gcov` data files

gcov uses three files for doing profiling. The names of these files are derived from the original source file by substituting the file suffix with either .bb, .bbg,or .da. All of these files are placed in the same directory as the source file, and contain data stored in a platform-independent method.

The .bb and .bbg files are generated when the source file is compiled with the GNU CC ‘-ftest-coverage’ option. The .bb file contains a list of source files (including headers), functions within those files, and line numbers corresponding to each basic block in the source file.

The .bb file format consists of several lists of 4-byte integers which correspond to the line numbers of each basic block in the file. Each list is terminated by a line number of 0. A line number of -1 is used to designate that the source file name (padded to a 4-byte boundary and followed by another -1) follows. In addition, a line number of -2 is used to designate that the name of a function (also padded to a 4-byte boundary and followed by a -2) follows.

The .bbg file is used to reconstruct the program flow graph for the source file. It contains a list of the program flow arcs (possible branches taken from one basic block to another) for each function which, in combination with the .bb file, enables gcov to reconstruct the program flow.

In the .bbg file, the format is the following.

    number of basic blocks for function #0 (4-byte number)
    total number of arcs for function #0 (4-byte number)
    count of arcs in basic block #0 (4-byte number)
    destination basic block of arc #0 (4-byte number)
    flag bits (4-byte number)
    destination basic block of arc #1 (4-byte number)
    flag bits (4-byte number)
    ...
    destination basic block of arc #N (4-byte number)

    flag bits (4-byte number)
    count of arcs in basic block #1 (4-byte number)
    destination basic block of arc #0 (4-byte number)
    flag bits (4-byte number)
    ...

A -1 (stored as a 4-byte number) is used to separate each function’s list of basic blocks, and to verify that the file has been read correctly.

The .da file is generated when a program containing object files built with the GNU CC ‘-fprofile-arcs’ option is executed. A separate .da file is created for each source file compiled with this option, and the name of the .da file is stored as an absolute pathname in the resulting object file. This path name is derived from the source file name by substituting a .da suffix.

The format of the .da file is fairly simple. The first 8-byte number is the number of counts in the file, followed by the counts (stored as 8-byte numbers). Each count corresponds to the number of times each arc in the program is executed. The counts are cumulative; each time the program is executed, it attemps to combine the existing .da files with the new counts for this invocation of the program. It ignores the contents of any .da files whose number of arcs doesn’t correspond to the current program, and merely overwrites them instead.

All three of these files use the functions in gcov-io.h to store integers; the functions in this header provide a machine independent mechanism for storing and retrieving data from a stream.

Top|Contents|Index|Previous|Next